package com.ustb.springboot.common.utils;


import javax.servlet.http.HttpServletRequest;

/**
 * 根据传入requet请求中的token信息获取username和userId
 *
 * @author pyn 2022/5/14
 */
public class TokenUtil {
    //解析token中的id信息
    public static Integer getId(HttpServletRequest request) {
        String token = request.getHeader("token");
        Integer id = Integer.parseInt(JwtUtil.parserJWToken(token).get("id").toString());
        return id;
    }

    //解析token中的username信息
    public static String getName(HttpServletRequest request) {
        String token = request.getHeader("token");
        String username = JwtUtil.parserJWToken(token).get("username").toString();
        return username;
    }
}
